package operations;

import book.Book;
import book.Booklist;

import java.util.Scanner;

public class Addoperation implements Operation{
    public void work(Booklist booklist){
        System.out.println("新增图书......");
        //1.先判断书架是否放满
        int count = booklist.getUesdSize();

        if(count == booklist.getBooks().length){
            System.out.println("书架已经放满，无法再新增图书");
            return;
        }

        Scanner scanner = new Scanner(System.in);

        System.out.println("请输入书名：");
        String name = scanner.nextLine();

        System.out.println("请输入作者：");
        String authr = scanner.nextLine();

        System.out.println("请输入图书的类型：");
        String type = scanner.nextLine();

        System.out.println("请输入图书的价格：");
        int price = scanner.nextInt();

        for (int i = 0;i < booklist.getUesdSize();i++){
            if ( booklist.getBook(i).getName().equals(name)){
                System.out.println("该书已存在，不可再添加");
                return;
            }
        }

        Book book = new Book(name,authr,price,type);
        booklist.setBook(booklist.getUesdSize(),book);
        booklist.setUesdSize(booklist.getUesdSize()+1);
        System.out.println("新增成功......");
    }
}
